package com.lz.football.module.playerCenter.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.global.GlobalDef;
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.model.goods.vo.PlayerStarVo;
	import com.liangzhong.model.playerCenter.vo.PlayerVo;
	import com.lz.football.module.playerCenter.ListItem;
	
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	
	import lz.controls.managers.TipsManager;
	import lz.controls.nick.ClassUtils;

	/**
	 * 球员中心球员item 
	 * @author Administrator
	 * 
	 */	
	public class PlayerCenterPlayerItem extends ListItem implements /*IComponent, IItemMouseEvent,*/IPlayerCenterItem
	{
//		/**
//		 * 
//		 */
//		private var _skin:MovieClip;
//		/**
//		 *效果 
//		 */
//		private var frame:MovieClip;
//		/**
//		 *容器 
//		 */
//		private var contain:MovieClip;
//		/**
//		 *位置 
//		 */
//		private var _place:TextField;
//		/**
//		 *号码 
//		 */
//		private var _number:TextField;
//		/**
//		 *颜色 
//		 */
//		private var playerColorBg:MovieClip;
//		/**
//		 * 
//		 */
//		private var _data:Object;
//		/**
//		 *状态  
//		 */
//		private var buff:MovieClip;
//		private var _select:Boolean;
		/**
		 * 
		 */
		private var _dragImage:PlayerCenterPlayerItem;
//		private var _callBack:Function;
		private var _selectFunction:Function;
		
		/**
		 *tips 
		 */
		private var _tips:String;
		public function PlayerCenterPlayerItem()
		{
			super();
		}
		
//		public function initUI(view:Object=null):void
//		{
//			_skin = Reflection.createInstance("com.lz.commonUI.playerItem");
//			this.addChild(_skin);
//			frame = _skin.frame;
//			_place = _skin._place;
//			_number = _skin._number
//			contain = _skin.contain;
//			buff = _skin.buff;
//			playerColorBg = _skin.playerColorBg;
//			frame.visible = false;
//			frame.mouseChildren = false;
//			frame.mouseEnabled = false;
//			
//		}
		
		override public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.MOUSE_DOWN,onDownHandlre);
			this.addEventListener(MouseEvent.MOUSE_UP,onUpHandlre);
			this.addEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
			this.addEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
			
			
		}
		
		protected function onupHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			if(_selectFunction != null)_selectFunction(this);
			if(this.stage)
			{
				this.stage.removeEventListener(MouseEvent.MOUSE_MOVE,onStageMoveHandler);
				this.stage.removeEventListener(MouseEvent.MOUSE_UP,onupHandler);
			}
			if(_dragImage == null)return;
			_dragImage.stopDrag();
			
			if(_dragImage != null)
			{
				if(_dragImage.parent)
				{
					_dragImage.parent.removeChild(_dragImage);
				}
				_dragImage.stopDrag();
				//				_dragImage.clear();
				var dis:DisplayObject = _dragImage.dropTarget;
				var target:IPlayerCenterItem = ClassUtils.getClass(dis,IPlayerCenterItem);
				if(callBack != null)
				{
					callBack(this,target as PlayerCenterPlayerItem);
				}
				if(_dragImage.parent)_dragImage.parent.removeChild(_dragImage);
			}
		}
		
		protected function onStageMoveHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			if(_dragImage == null) 
			{
				_dragImage = new PlayerCenterPlayerItem();;
				_dragImage.initUI();
			}
//			DisplayObjectUtil.removeAllChildren(_dragImage);
//			var bitmapData :BitmapData 	= _data.starVo.bitmapData;
//			var bitmap :Bitmap = new Bitmap(bitmapData);
//			_dragImage.addChild(bitmap);
			_dragImage.data = data;
			_dragImage.startDrag();
			_dragImage.alpha = 0.7;
			_dragImage.x =this.stage.mouseX  - (_dragImage.width>>1);
			_dragImage.y = this.stage.mouseY - (_dragImage.height >>1);
			GlobalDef.GameStage.addChild(_dragImage);
		}
		
		protected function onUpHandlre(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			
		}
		
		protected function onDownHandlre(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			this.stage.addEventListener(MouseEvent.MOUSE_MOVE,onStageMoveHandler);
			this.stage.addEventListener(MouseEvent.MOUSE_UP,onupHandler);
			TipsManager.hide();
		}
		
		override public function removeEvtListener():void
		{
			if(this.stage)
			{
				this.stage.removeEventListener(MouseEvent.MOUSE_MOVE,onStageMoveHandler);
				this.stage.removeEventListener(MouseEvent.MOUSE_UP,onupHandler);
			}
			this.removeEventListener(MouseEvent.MOUSE_DOWN,onDownHandlre);
			this.removeEventListener(MouseEvent.MOUSE_UP,onUpHandlre);
			this.removeEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
			this.removeEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
		}
		
		override public function destroyView():void
		{
			removeEvtListener();
			_selectFunction = null;
			
			reSet();
			DisplayObjectUtil.removeAllChildren(contain);
			if(_dragImage != null)_dragImage.destroyView();
			_dragImage = null;
//			playerColorBg = null;
			if(this.parent)this.parent.removeChild(this);
			super.destroyView();
		}
		
		override public function onMouseRollOut(event:MouseEvent):void
		{
			TipsManager.hide();
			if(select)return;
//			frame.visible = false;
			
				
		}
		
		override public function onMouseRollOver(event:MouseEvent):void
		{
			if(data is PlayerVo)
			{
				TipsManager.show(TipsConst.PLAYERCARDTIPSBYPLAYER,{data:data,type:2},20,10,true);
			}else if(data is PlayerStarVo)
			{
				TipsManager.show(TipsConst.PLAYERCARDTIPS,data,15,15,false);
			}
			if(select)return;
//			frame.visible = true;
			
		}
		
		override public function onMouseClick(event:MouseEvent):void
		{
		}
		
//		public function get data():Object
//		{
//			return _data;
//		}
		override public function set data(value:Object):void
		{
			super.data = value;
			var vo:PlayerVo = data as PlayerVo;
//			_tips = vo.starVo.pname + "";
			_tips = "体力：" + vo.physical + "/" + vo.maxphysical;
		}
//		public function set data(value:Object):void
//		{
//			
//			reSet();
//			_data = value;
//			if(!(value is PlayerVo))return;
//			DisplayObjectUtil.removeAllChildren(contain);
//			var vo:PlayerVo = _data as PlayerVo;
//			_place.text = vo.place_String + "";
//			_number.text = vo.number + "";
//			if(vo.starVo == null)return;
//			_tips = vo.starVo.pname + "";
//			if(vo.status == 1)
//			{
//				buff.visible = false;
//			}else
//			{
//				buff.visible = true;
//			}
//			var bitmapData :BitmapData 	= vo.starVo.bitmapData;
//			var bitmap :Bitmap = new Bitmap(bitmapData);
//			playerColorBg.gotoAndStop(vo.color);
//			contain.addChild(bitmap);
//			addEvtListener();
//		}
		
//		/**
//		 *更新buff状态 
//		 * 
//		 */
//		public function updataBuff():void
//		{
//			var vo:PlayerVo = _data as PlayerVo;
//			if(vo.status == 1)
//			{
//				buff.visible = false;
//			}else
//			{
//				buff.visible = true;
//			}
//		}
//		public function get tips():String
//		{
//			return _tips;
//		}
//		
//		public function set tips(value:String):void
//		{
//			_tips = value;
//		}

//		/**
//		 *选中状态  
//		 */
//		public function get select():Boolean
//		{
//			return _select;
//		}
//
//		/**
//		 * @private
//		 */
//		public function set select(value:Boolean):void
//		{
//			_select = value;
//			if(_select)
//			{
//				frame.visible = true;
//			}else
//			{
//				frame.visible = false;
//			}
//			
//		}
		/**
		 *获得坐标  
		 * @param $alternateId替补球员Id
		 * 
		 */		
		public function setPlaceDetail($alternateItem:PlayerCenterPlayerItem):void
		{
			
		}

//		public function get callBack():Function
//		{
//			return _callBack;
//		}
//
//		public function set callBack(value:Function):void
//		{
//			_callBack = value;
//		}

		/**
		 *重置 
		 * 
		 */
		public function reSet():void
		{
//			super.reSet();
//			buff.visible = false;
			select = false;
//			frame.visible = false;
//			_place.text = "";
//			_number.text = "";
			_tips = null;
		}

		/**
		 *点击时回调 
		 */
		public function get selectFunction():Function
		{
			return _selectFunction;
		}

		/**
		 * @private
		 */
		public function set selectFunction(value:Function):void
		{
			_selectFunction = value;
		}

	}
}